package com.ruoyi.web.controller.message;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.message.domain.TMessageUser;
import com.ruoyi.message.service.ITMessageUserService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 消息用户关联Controller
 *
 * @author Bandit
 * @date 2022-11-01
 */
@RestController
@RequestMapping("/message/MessageUser")
public class TMessageUserController extends BaseController
{
    @Autowired
    private ITMessageUserService tMessageUserService;

    /**
     * 查询消息用户关联列表
     */

    @GetMapping("/list")
    public TableDataInfo list(TMessageUser tMessageUser)
    {
        startPage();
        List<TMessageUser> list = tMessageUserService.selectTMessageUserList(tMessageUser);
        return getDataTable(list);
    }

    /**
     * 导出消息用户关联列表
     */
    @PreAuthorize("@ss.hasPermi('message:MessageUser:export')")
    @Log(title = "消息用户关联", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, TMessageUser tMessageUser)
    {
        List<TMessageUser> list = tMessageUserService.selectTMessageUserList(tMessageUser);
        ExcelUtil<TMessageUser> util = new ExcelUtil<TMessageUser>(TMessageUser.class);
        util.exportExcel(response, list, "消息用户关联数据");
    }

    /**
     * 获取消息用户关联详细信息
     */

    @GetMapping(value = "/{messageId}")
    public AjaxResult getInfo(@PathVariable("messageId") Long messageId)
    {
        return success(tMessageUserService.selectTMessageUserByMessageId(messageId));
    }

    /**
     * 获取消息用户关联详细信息
     */

    @GetMapping(value = "/user")
    public AjaxResult getCurrentUserMessages()
    {
        return success(tMessageUserService.selectMessageListByUserId());
    }


    /**
     * 获取消息用户关联详细信息
     */

    @GetMapping(value = "/user/{userId}")
    public AjaxResult getUserMessages(@PathVariable("userId") Long userId)
    {
        return success(tMessageUserService.selectMessageListByUserId(userId));
    }


    /**
     * 新增消息用户关联
     */
    @PreAuthorize("@ss.hasPermi('message:MessageUser:add')")
    @Log(title = "消息用户关联", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody TMessageUser tMessageUser)
    {
        return toAjax(tMessageUserService.insertTMessageUser(tMessageUser));
    }

    /**
     * 修改消息用户关联
     */
    @PreAuthorize("@ss.hasPermi('message:MessageUser:edit')")
    @Log(title = "消息用户关联", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody TMessageUser tMessageUser)
    {
        return toAjax(tMessageUserService.updateTMessageUser(tMessageUser));
    }

    /**
     * 删除消息用户关联
     */
    @PreAuthorize("@ss.hasPermi('message:MessageUser:remove')")
    @Log(title = "消息用户关联", businessType = BusinessType.DELETE)
	@DeleteMapping("/{messageIds}")
    public AjaxResult remove(@PathVariable Long[] messageIds)
    {
        return toAjax(tMessageUserService.deleteTMessageUserByMessageIds(messageIds));
    }
}
